const fs = require("fs");
const path = require("path");

function mkdirSync(url, data) {
  const currDirPath = path.resolve(__dirname, '../DataHome') + url
  const currDataPath = path.resolve(__dirname, '../DataHome') + url + "/index.json"
  return new Promise((resolve, reject) => {
    fs.mkdirSync(
      currDirPath,
      { recursive: true }
    );
    setTimeout(() => {
      fs.writeFile(
        currDataPath,
        JSON.stringify(data),
        (err, data) => {
          if (err) {
            reject("创建json文件失败");
           
          }
          resolve(data);
          console.log("添加数据成功");
        
        }
      );
    }, 300);
  });
}

module.exports = mkdirSync;
